#include "StdAfx.h"
#include "Interpreter.h"

Interpreter::Interpreter(void)
{
}

Interpreter::~Interpreter(void)
{
}

int Interpreter::Run(vector<string> tokens, int poz, BaseDuck * duck)
{
	for(int i = poz; i < tokens.size(); i++)
	{
		if(tokens[i] == "right")
		{
			cout << "right \n";
		}
		else if(tokens[i] == "fly")
		{
			if(duck->GetFly())
			{
				cout << "fly \n";
			}
		}
		else if(tokens[i] == "quack")
		{
			if(duck->GetQuack())
			{
				cout << "quack \n";
			}
		}
		else if(tokens[i] == "}")
		{
			return i;
		}
		else if(tokens[i] == "while")
		{
			i += 2;
			int var, newPoz;

			var = atoi(tokens[i].c_str());

			for(int j = 0; j < var; j++)
			{
				newPoz = Run(tokens, ++i, duck);
			}

			i = newPoz;
		}
	}
}